import NProgress from 'nprogress'

const progress = NProgress.configure({
    showSpinner: true
})

export function showProgress() {
    progress.start();
}

export function hideProgress() {
    progress.done();
}

export function dictToArray(dict) {
    return Object.entries(dict).map(([key, value]) => ({key, value}))
}

export function enumToArray(dict) {
    return Object.values(dict)
}

export function convertSortParam(orderMap) {
    return orderMap.map(item => `${item.orderColumn},${item.orderType}`).join(orderMap.length > 1 ? ';' : '')
}

/**
 * 判断path是否为外链
 * @param {string} path
 * @returns {Boolean}
 */
export function isExternal(path) {
    return /^(https?:|mailto:|tel:)/.test(path)
}

export function checkPwdStrong(password) {
    var modes = 0;
    // 正则表达式校验
    if (password.length < 1) return modes;
    if (/\d/.test(password)) modes++; // 数字
    if (/[a-z]/.test(password)) modes++; // 小写
    if (/[A-Z]/.test(password)) modes++; // 大写
    if (/\W/.test(password)) modes++; // 特殊字符

    // 逻辑处理
    switch (modes) {
        case 1:
            return 1;
            break;
        case 2:
            return 2;
            break;
        case 3:
        case 4:
            return password.length < 6 ? 3 : 4;
            break;
    }
    return modes
}
